package com.shujia.flink.core

import org.apache.flink.api.scala._

object BatchWordCount {

  def main(args: Array[String]): Unit = {

    //获取批处理环境
    val env = ExecutionEnvironment.getExecutionEnvironment
    //读取文件创建DataSet
    val lineDS: DataSet[String] = env.readTextFile("flink/data/words.txt")

    val wordsDS = lineDS.flatMap(_.split(","))

    val kvDS = wordsDS.map(word => (word, 1))

    val groupDS = kvDS.groupBy(0)

    //指定列求和
    val countDS = groupDS.sum(1)

    countDS.print()
  }

}
